package blog.controller;

import blog.entity.Consumer;
import blog.entity.Tag;
import blog.service.back.ConsumerBackService;
import blog.service.client.ConsumerClientService;
import blog.service.client.TagClientService;
import blog.vo.back.ByConsumerUuidGetConsumerInfoVO;
import blog.vo.back.EmailLoginVO;
import blog.vo.back.PhoneNumberLoginVO;
import blog.vo.client.AddConsumerVO;
import blog.vo.client.AddTagReadCountVO;
import blog.vo.client.PhoneNumberOrEmailVO;
import blog.vo.common.PaginationVO;
import blog.vo.common.ResponseListObjectVO;
import blog.vo.common.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 　　* @description: TODO
 * 　　* @param
 * 　　* @return
 * 　　* @throws
 * 　　* @author Administrator
 * 　　* @date $ $
 *
 */
@RestController
@RequestMapping("/consumer")
public class ConsumerController {
    @Autowired
    private ConsumerClientService consumerClientService;

    private Consumer consumer;

    @PostMapping("/login")
    public ResponseVO<Consumer> login(@RequestBody PhoneNumberOrEmailVO phoneNumberOrEmail) {
        if (phoneNumberOrEmail.getPhoneNumberOrEmail().contains("@qq.com")) {
            consumer = consumerClientService.emailLogin(new EmailLoginVO(phoneNumberOrEmail.getPhoneNumberOrEmail(), phoneNumberOrEmail.getConsumerPassword()));
        }
        else {
            consumer = consumerClientService.phoneNumberLogin(new PhoneNumberLoginVO(phoneNumberOrEmail.getPhoneNumberOrEmail(), phoneNumberOrEmail.getConsumerPassword()));
        }
        if (consumer == null) {
            return new ResponseVO<Consumer>(1001, "账号或者密码错误", null);
        }
       else {
            return new ResponseVO<Consumer>(200, "ok", consumer);
        }
    }

    @PostMapping("/add-consumer")
    public String addTagReadCount(@RequestBody AddConsumerVO addConsumerVO){
        String consumerUuid = consumerClientService.addConsumer(addConsumerVO);
        return consumerUuid;
    }

    @PostMapping("/by-consumer-uuid-get-consumer-info")
    public Consumer byConsumerUuidGetConsumerInfo(@RequestBody ByConsumerUuidGetConsumerInfoVO byConsumerNameGetConsumerInfoVO){
        return consumerClientService.byConsumerUuidGetConsumerInfo(byConsumerNameGetConsumerInfoVO);
    }
}
